package jtest.com.cpi.cornpp.instructionsforecasts.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import junit.framework.TestCase;

import com.cpi.cornpp.customer.view.CustomerView;
import com.cpi.cornpp.instructionsforecasts.exception.InstructionsForecastsException;
import com.cpi.cornpp.instructionsforecasts.service.InstructionForecastsService;
import com.cpi.cornpp.instructionsforecasts.view.InstructionsForecastsView;
import com.cpi.cornpp.product.view.ProductView;

public class InstructionForecastsServiceTest extends TestCase {
	
	InstructionForecastsService instructionForecastsService = null;
	
	public InstructionForecastsServiceTest(String name) {
		super(name);
	}

	protected void setUp() throws Exception {
		instructionForecastsService = new InstructionForecastsService();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testList() {
		CustomerView customerView = null;
		ProductView productView = null;
		List productViews = null;
		List forecastViews = null;
		Iterator iterator = null;
		InstructionsForecastsView instructionsForecastsView = null;
		try {
			productViews = new ArrayList(6);
			customerView = new CustomerView();
			customerView.setCustomerId("115437");
			
			productView = new ProductView();
			productView.setProductId("01050009OB");
			productViews.add(productView);
			
			productView = new ProductView();
			productView.setProductId("02001003DH");
			productViews.add(productView);
			
			productView = new ProductView();
			productView.setProductId("11100100BN");
			productViews.add(productView);
			
			productView = new ProductView();
			productView.setProductId("15735006NM");
			productViews.add(productView);
			
			productView = new ProductView();
			productView.setProductId("26010006NM");
			productViews.add(productView);
			
			productView = new ProductView();
			productView.setProductId("26142000UO");
			productViews.add(productView);
			
			forecastViews = instructionForecastsService.list(productViews, customerView, -1, 1, 2010);
			iterator = forecastViews.iterator();
			while(iterator.hasNext()){
				instructionsForecastsView = (InstructionsForecastsView)iterator.next();
				System.out.println("Product: "+ instructionsForecastsView.getItemId() + "; Month: "+ instructionsForecastsView.getMonth()+"; Year: "+instructionsForecastsView.getYear()+"; Contracted: "+instructionsForecastsView.getContracted());
			}
		} catch (InstructionsForecastsException instructionsForecastsException) {
			fail(instructionsForecastsException.getMessage());
		}
	}
}